require('../system/home/index.php');
$K = new Index('magic-shell');
$cfg = $K->config->get('locoyspider');
new locoyspider($cfg);
class locoyspider
{
public $cfg = array();
public function __construct($cfg)
{
$this->cfg = $cfg;
if(!$this->cfg['isopen']){
exit('Locoyspider Api Closed!');
}else if(!$Authorize = trim($_REQUEST['Authorize'])){
exit('Authorize error');
}else if($this->cfg['Authorize'] != $Authorize){
exit('Authorize error');
}else if(!$api = trim($_REQUEST['api'])){
$api = 'index';
}else if(!in_array($api, array('index', 'article', 'cate','city', 'area', 'shop', 'shopcate', 'hotel', 'product', 'tuan', 'photo', 'member'))){
exit('Api error');
}
$this->$api();
}
public function index()
{
echo "HQ Locoyspider Api success";
}
public function article()
{
if(!$data = K::$system->_gpc->p('data')){
exit('data error');
}else{
$data['from'] = 'article';
$attachcfg = K::$system->config->get('attach');
if(preg_match('/attachs\/photo\/\d \/\w \.(jpg|png|gif|jpeg)/i', $data['content'], $match)){
if($this->cfg['Autothumb']){
$thumb = substr($match[0], 8);
}
$data['content'] = preg_replace('/attachs\/photo\/(\d )\/(\w )\.(jpg|png|gif|jpeg)/i', $attachcfg['attachurl']."/photo/$1/$2.$3", $data['content']);
}
if(empty($data['thumb']) && $thumb){
$data['thumb'] = $thumb;
}
if($article_id = K::M('article/article')->create($data)){
echo 'success';
}else{
K::$system->error->json();
}
}
}
public function cate()
{
$tree = '';
if($cats = K::M('article/cate')->tree('article')){
foreach($cats as $v){
$tree .= $v['cat_id'].':'.$v['title'].';';
foreach((array)$v['children'] as $vv){
$tree .= $vv['cat_id'].': '.$vv['title'].';';
foreach((array)$vv['children'] as $vvv){
$tree .= $vvv['cat_id'].': '.$vvv['title'].';';
}
}
}
}
echo $tree;
}
public function shopcate()
{
$tree = '';
$pid = (int)K::$system->gpc->p('pid');
if($cats = K::M('shop/cate')->childrens($pid)){
foreach($cats as $v){
$tree .= $v['cat_id'].':'.$v['title'].';';
}
}
echo $tree;
}
评论